/*
#    Copyright By Schips, All Rights Reserved
#    https://gitee.com/schips/
#
#    File Name:  client.c
#    Created  :  Thu 26 Mar 2020 05:11:03 PM CST
*/

#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
 
int main(int argc, char* argv[])
{
    int socketfd;
    socklen_t n;
    socketfd = socket(AF_INET, SOCK_DGRAM, 0);
     
    struct sockaddr_in serv_addr;
    struct sockaddr_in addr;
         
    bzero((char *)&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(7779);

    char buf[64] = {0};
    //write(socketfd, "client message", sizeof("client message"));
    sendto(socketfd, "client message", sizeof("client message"),0, (struct sockaddr *)&serv_addr, sizeof(serv_addr));

    memset(buf, 0, sizeof(buf));
    //read(socketfd, buf, sizeof(buf));
    recvfrom(socketfd, buf, sizeof(buf), 0, (struct sockaddr *)&serv_addr, &n);
    printf("%u %s\n",n ,buf);
    return 0;
 
}
